﻿using System;
using System.Text;

namespace SharpSoft.Data.GSQL
{
    public class GSQLCommandScript
    {
        public GSQLCommandScript()
        {

        }
        public GSQLCommandScript(string gsqltxt)
        {
            CommandText = gsqltxt;
        }
        internal SQLCommandScript ToSql(SQLTextGenerator stg)
        {
            GSQLAnalyzer GLA = new GSQLAnalyzer(this.CommandText);
            var stams = GLA.ReadStatements();
            StringBuilder sb = new StringBuilder();
            foreach (var item in stams)
            {
                sb.Append(stg.ProcessStatement(item))
                    .AppendLine(";");
            }
            return new SQLCommandScript(sb.ToString());
        }

        public string CommandText { get; set; }

        public static implicit operator string(GSQLCommandScript gsql)
        {
            return gsql.CommandText;
        }
        public static implicit operator GSQLCommandScript(string gsqltxt)
        {
            return new GSQLCommandScript() { CommandText = gsqltxt };
        }
    }
}